{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import hgvs.parser\n",
    "import hgvs.dataproviders.uta\n",
    "import hgvs.variantmapper"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "hp = hgvs.parser.Parser()\n",
    "hdp = hgvs.dataproviders.uta.connect()\n",
    "am = hgvs.variantmapper.AssemblyMapper(hdp,\n",
    "                                           assembly_name='GRCh37',\n",
    "                                           alt_aln_method='splign')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "g_hgvs = 'NC_000001.10:g.150550916_150550920delGACAAinsCAATACC'\n",
    "g_var = hp.parse_hgvs_variant(g_hgvs)\n",
    "c_var = am.g_to_c(g_var, 'NM_182763.2')\n",
    "p_var = am.c_to_p(c_var)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false,
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(SequenceVariant(ac=NC_000001.10, type=g, posedit=150550916_150550920delGACAAinsCAATACC),\n",
       " SequenceVariant(ac=NM_182763.2, type=c, posedit=688+399_688+403delTTGTCinsGGTATTG),\n",
       " SequenceVariant(ac=NP_877495.1, type=p, posedit=?))"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "g_var, c_var, p_var"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['NC_000001.10:g.150550916_150550920delGACAAinsCAATACC',\n",
       " 'NM_182763.2:c.688+399_688+403delTTGTCinsGGTATTG',\n",
       " 'NP_877495.1:p.?']"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[str(v) for v in (g_var, c_var, p_var)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "SequenceVariant(ac=NM_021960.4, type=c, posedit=737dupT)"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import hgvs.normalizer\n",
    "hn = hgvs.normalizer.Normalizer(hdp)\n",
    "hn.normalize(hp.parse_hgvs_variant('NM_021960.4:c.735_736insT'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "NM_021960.4:c.736_740delATGTCinsGGTATTG: Variant reference (ATGTC) does not agree with reference sequence (TTGTC)\n"
     ]
    }
   ],
   "source": [
    "import hgvs.validator\n",
    "hv = hgvs.validator.Validator(hdp)\n",
    "try:\n",
    "    hv.validate(hp.parse_hgvs_variant('NM_021960.4:c.736_740delATGTCinsGGTATTG'))\n",
    "except Exception as e:\n",
    "    print(e)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
